package org.centsuse.intention_spring.invention.runner;

import lombok.extern.slf4j.Slf4j;
import org.centsuse.intention_spring.invention.config.scenes.processor.CommonProcessor;
import org.centsuse.intention_spring.invention.entities.contexts.ContextManager;
import org.centsuse.intention_spring.invention.factory.ModelFactory;
import org.centsuse.intention_spring.invention.factory.SceneFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class ProcessorRunner implements ApplicationRunner {

    @Autowired
    private ContextManager contextManager;

    @Autowired
    private SceneFactory sceneFactory;

    @Autowired
    private ModelFactory modelFactory;

    @Autowired
    private ApplicationContext applicationContext;

    @Override
    public void run(ApplicationArguments args) throws Exception {

        log.info("[ProcessorRunner][run]Running processor...");
        // 处理sceneFactory
        sceneFactory.loadProcessors();

        log.info("[ProcessorRunner][run]Running processor..., contextManager: {}", modelFactory);
        log.info("[ProcessorRunner][run]Running processor..., contextManager: {}", sceneFactory);
        log.info("[ProcessorRunner][run]Running processor..., contextManager: {}", contextManager);
        CommonProcessor commonProcessor = applicationContext.getBean(CommonProcessor.class);
        commonProcessor.setContextManager(contextManager);
        commonProcessor.setModelFactory(modelFactory);
        commonProcessor.setSceneConfigMap(sceneFactory.getSceneConfiguration().getSceneConfigMap());
        log.info("[ProcessorRunner][run]Running processor..., commonProcessor: {}", commonProcessor);
    }
}
